<?php

/**
 * 
 * @author yuxun
 *
 */
class GameShopController extends AdminBaseController {
	
	public function index(){
		$this->setTitle('商城商品列表', '数据需从Excel导入');
	
		$filter = new PubFilter();
		$grid   = new PubGrid();

        $filter->addFilter('item_id', 'input', '物品ID')
               ->addFilter('item_name', 'input', '物品名称');

		$url = PubFunc::buildUrl("/oss/?r=gameShop/importGoods");
		$filter->addImport('商城商品导入',$url);
		
		$params = $filter->get();
		$header = GameShopService::indexHeader();
		if(PubFunc::isAjax()){
			$result = GameShopService::indexData($params);
			
			$this->out = array(
					'count'     => $result['count'],
					'data'      => $result['data'],
					'result'    => true
			);
			$this->outType = 'json';
		}else{
			$order  = 'id';
			$params['m'] = PubRequest::R('m');
			$url = PubFunc::ajaxUrl("?r=gameShop/index", $params);
			$grid->addGrid($header, $url, array(
					'name'=>'数据',
					'order'=>array($order, 'asc'),
					'type'=>'gameShop/index',
			));
			
			$this->out['grid'] = $grid->show();
			$this->out['filter'] = $filter->show();
			
			$this->out['downUrl'] = '/public/template/game_shop.xlsx';
			$user = AccAuth::me();
			if($user['IsAdmin'] == 1 || $user['Identity'] == 2){
				$this->out['table'] = 'game_shop';
			}
		}
	}
	
	public function delete(){
		$id = $this->R('id');
	
		$result = GameShopService::delete($id);
	
		if($result !== false){
			$this->showMessage('删除成功', PubFunc::buildUrl("/oss/?r=gameShop/index"));
		}else{
			$this->showMessage('删除失败');
		}
	}
	
	public function importGoods(){
		$upload = GameShopService::upload($_FILES);
		if($upload["status"] == 1){ //上传成功
			$filePath = $upload['data'];
			$data = LibExcel::import($filePath);
			$result = GameShopService::xlsAdd($data);
			$out = $result;
		}else{
			$out = $upload; //上传失败
		}
		
		$this->out = $out;
		$this->outType = 'json';
	}

    

    

    
}